Exception Handling ^^^^^ **Definition:** * This smell occurs when a test method explicitly a passing or failing of a test method is dependent on the production method throwing an exception. Developers should utilize JUnit's exception handling to automatically pass/fail the test instead of writing custom exception handling code or throwing an exception. **Code Example:** .. code-block:: java @Test public void realCase() { Point p34 = new Point("34", 556506.667, 172513.91, 620.34, true); Point p45 = new Point("45", 556495.16, 172493.912, 623.37, true); Point p47 = new Point("47", 556612.21, 172489.274, 0.0, true); Abriss a = new Abriss(p34, false); a.removeDAO(CalculationsDataSource.getInstance()); a.getMeasures().add(new Measure(p45, 0.0, 91.6892, 23.277, 1.63)); a.getMeasures().add(new Measure(p47, 281.3521, 100.0471, 108.384, 1.63)); try { a.compute(); } catch (CalculationException e) { Assert.fail(e.getMessage()); } // test intermediate values with point 45 Assert.assertEquals("233.2405", this.df4.format(a.getResults().get(0).getUnknownOrientation())); Assert.assertEquals("233.2435", this.df4.format(a.getResults().get(0).getOrientedDirection())); Assert.assertEquals("-0.1", this.df1.format( a.getResults().get(0).getErrTrans())); // test intermediate values with point 47 Assert.assertEquals("233.2466", this.df4.format(a.getResults().get(1).getUnknownOrientation())); Assert.assertEquals("114.5956", this.df4.format(a.getResults().get(1).getOrientedDirection())); Assert.assertEquals("0.5", this.df1.format( a.getResults().get(1).getErrTrans())); // test final results Assert.assertEquals("233.2435", this.df4.format(a.getMean())); Assert.assertEquals("43", this.df0.format(a.getMSE())); Assert.assertEquals("30", this.df0.format(a.getMeanErrComp())); } **References:** .. admonition:: Quality attributes * :octicon:`file-code;1em` - Code Example * :octicon:`comment-discussion;1em` - Cause and Effect * :octicon:`graph;1em` - Frequency * :octicon:`sync;1em` - Refactoring * `An Exploratory Study on the Refactoring of Unit Test Files in Android Applications `_ :octicon:`comment-discussion;1em` :octicon:`sync;1em` * `Automatic Identification of High-Impact Bug Report by Product and Test Code Quality `_ * `Automatic generation of smell-free unit tests `_ :octicon:`comment-discussion;1em` * `Characterizing High-Quality Test Methods: A First Empirical Study `_ :octicon:`graph;1em` * `Handling Test Smells in Python: Results from a Mixed-Method Study `_ * `Investigating Test Smells in JavaScript Test Code `_ :octicon:`graph;1em` * `On the Distribution of "Simple Stupid Bugs" in Unit Test Files: An Exploratory Study `_ * `On the diffusion of test smells and their relationship with test code quality of Java projects `_ :octicon:`graph;1em` * `On the distribution of test smells in open source Android applications: an exploratory study `_ :octicon:`file-code;1em` :octicon:`graph;1em` * `On the influence of Test Smells on Test Coverage `_ * `On the test smells detection: an empirical study on the jnose test accuracy `_ :octicon:`graph;1em` * `PyNose: A Test Smell Detector For Python `_ :octicon:`comment-discussion;1em` :octicon:`graph;1em` * `Pytest-Smell: a smell detection tool for Python unit tests `_ :octicon:`graph;1em` * `Refactoring Test Smells With JUnit 5: Why Should Developers Keep Up-to-Date? `_ :octicon:`file-code;1em` :octicon:`comment-discussion;1em` :octicon:`graph;1em` :octicon:`sync;1em` * `Refactoring Test Smells: A Perspective from Open-Source Developers `_ :octicon:`file-code;1em` :octicon:`sync;1em` * `Software Unit Test Smells `_ :octicon:`file-code;1em` * `TEMPY: Test Smell Detector for Python `_ :octicon:`graph;1em` * `Test Smell Detection Tools: A Systematic Mapping Study `_ * `TestAXE: Automatically Refactoring Test Smells Using JUnit 5 Features `_ :octicon:`graph;1em` :octicon:`sync;1em` * `The secret life of test smells-an empirical study on test smell evolution and maintenance `_ :octicon:`graph;1em` * `Understanding Testability and Test Smells `_ * `Understanding practitioners’ strategies to handle test smells: a multi-method study `_ :octicon:`comment-discussion;1em` :octicon:`sync;1em` * `What the Smell? An Empirical Investigation on the Distribution and Severity of Test Smells in Open Source Android Applications `_ :octicon:`file-code;1em` :octicon:`graph;1em` * `tsDetect: an open source test smells detection tool `_